﻿using Bll;
using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Myproject.BSM.Ashx.PcBase
{
    /// <summary>
    /// JoinAjax 的摘要说明
    /// </summary>
    public class JoinAjax : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (!string.IsNullOrEmpty(cookieHelp.AdminId))
            {
                if (new AdminBLL().ExistsByAdminName(cookieHelp.AdminName) && new AdminBLL().ExistsByAdminId(cookieHelp.AdminId))
                {

                    string dos = context.Request.Params["dos"];
                    string id;
                    #region swith do
                    switch (dos)
                    {
                        case "delete":
                            id = context.Request.QueryString["id"];
                            if (new JoinBLL().Delete(int.Parse(id)))
                            {
                                context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "删除成功！", "pc_base_joinList", "", "", false, "", ""));
                            }
                            else
                            {
                                context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "删除失败！", "pc_base_joinList", "", "", false, "", ""));
                            }
                            break;

                        case "show":
                            id = context.Request.QueryString["id"];
                            string show = context.Request.QueryString["show"];
                            if (id != "0")
                            {
                                JoinModel model = new JoinBLL().GetModel(int.Parse(id));
                                model.show = bool.Parse(show);
                                if (new JoinBLL().Update(model))
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改成功！", "pc_base_joinList", "", "", false, "", ""));
                                }
                                else
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改失败！", "pc_base_joinList", "", "", false, "", ""));
                                }
                            }
                            else
                            {
                                context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改失败！", "pc_base_joinList", "", "", false, "", ""));
                            }
                            break;

                        case "edit":
                            id = context.Request.Params["pc_base_JoinEdit_joinID"].Trim();
                            string title = context.Request.Params["pc_base_JoinEdit_title"].Trim();
                            string number = context.Request.Params["pc_base_JoinEdit_number"].Trim();
                            string money = context.Request.Params["pc_base_JoinEdit_money"].Trim();
                            string text = context.Request.Params["pc_base_JoinEdit_text"].Trim();
                            if (id == "0")
                            {
                                JoinModel model = new JoinModel();
                                model.title = title;
                                model.unmber = int.Parse(number);
                                model.money = money;
                                model.text = text;

                                if (new JoinBLL().Add(model) > 0)
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "新增招聘成功！", "pc_base_joinList", "", "", true, "", ""));
                                }
                                else
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "新增招聘失败！", "pc_base_joinList", "", "", true, "", ""));
                                }
                            }
                            else
                            {
                                JoinModel model = new JoinBLL().GetModel(Int32.Parse(id));
                                model.title = title;
                                model.unmber = int.Parse(number);
                                model.money = money;
                                model.text = text;
                                if (new JoinBLL().Update(model))
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改招聘成功！", "pc_base_joinList", "", "", true, "", ""));
                                }
                                else
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改招聘失败！", "pc_base_joinList", "", "", true, "", ""));
                                }
                            }
                            break;
                    }
                    #endregion
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(301, "登陆超时！", "", "", "", false, "/bsm/logFrom.aspx", "登陆超时！"));
                }
            }
            else
            {
                context.Response.Write(ReturnJsonHelp.BJUIajaxJson(301, "登陆超时！", "", "", "", false, "/bsm/logFrom.aspx", "登陆超时！"));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}